#include "faketriggers_manager.h"

bool UTIL_IsVectorEqual(Vector first, Vector second)
{
	if ((first.x == second.x) && (first.y == second.y) && (first.z == second.z)) return true;
	else return false;
}

Vector UTIL_CreateVector(float x, float y, float z)
{
	Vector vec = {x, y, z};
	return vec;
}

FakeTriggers::FakeTriggers()
{
}

FakeTriggers::~FakeTriggers()
{
}

bool FakeTriggers::Add(char *trigger_name, Vector mins, Vector maxs)
{
	if ((!Exists(trigger_name)) && (!Exists(mins, maxs)))
	{
		FakeTrigger new_trigger;
		new_trigger.trigger_name = trigger_name;
		new_trigger.mins = mins;
		new_trigger.maxs = maxs;
		trigger_list.push_back(new_trigger);
		return true;
	}
	else return false;
}

void FakeTriggers::Remove(char *trigger_name)
{
	for (std::vector<FakeTrigger>::iterator it = trigger_list.begin(); it != trigger_list.end(); ++it)
	{
		if (it->trigger_name == trigger_name)
		{
			trigger_list.erase(it);
			return;
		}
	}
}

void FakeTriggers::Remove(Vector mins, Vector maxs)
{
	for (std::vector<FakeTrigger>::iterator it = trigger_list.begin(); it != trigger_list.end(); ++it)
	{
		if ((UTIL_IsVectorEqual(it->mins, mins)) && (UTIL_IsVectorEqual(it->maxs, maxs)))
		{
			trigger_list.erase(it);
			return;
		}
	}
}

bool FakeTriggers::Exists(char *trigger_name)
{
	for (std::vector<FakeTrigger>::iterator it = trigger_list.begin(); it != trigger_list.end(); ++it)
	{
		if (it->trigger_name == trigger_name) return true;
	}
	return false;
}

bool FakeTriggers::Exists(Vector mins, Vector maxs)
{
	for (std::vector<FakeTrigger>::iterator it = trigger_list.begin(); it != trigger_list.end(); ++it)
	{
		if ((UTIL_IsVectorEqual(it->mins, mins)) && (UTIL_IsVectorEqual(it->maxs, maxs)))
			return true;
	}
	return false;
}

unsigned int FakeTriggers::Count()
{
	return trigger_list.size();
}
